import itertools

n = int(input())
numbers = input().split()

count = 0

# 检查一个字符串是否包含至少6个连续的6
def is_good_number(s):
    return '666666' in s

# 尝试所有可能的分组方式，优先处理能形成好数的组合
used = [False] * n
for i in range(n):
    if not used[i]:
        # 尝试单独一个数
        if is_good_number(numbers[i]):
            count += 1
            used[i] = True
            continue
        # 尝试两个数的组合
        for j in range(i + 1, n):
            if not used[j]:
                combined = numbers[i] + numbers[j]
                if is_good_number(combined):
                    count += 1
                    used[i] = used[j] = True
                    break
                combined = numbers[j] + numbers[i]
                if is_good_number(combined):
                    count += 1
                    used[i] = used[j] = True
                    break
        else:
            # 尝试三个数的组合
            for j in range(i + 1, n):
                if not used[j]:
                    for k in range(j + 1, n):
                        if not used[k]:
                            # 尝试所有排列组合
                            for perm in itertools.permutations([numbers[i], numbers[j], numbers[k]]):
                                combined = ''.join(perm)
                                if is_good_number(combined):
                                    count += 1
                                    used[i] = used[j] = used[k] = True
                                    break
                            if used[i]:
                                break
                    if used[i]:
                        break

print(count)